package zjitc.mapper;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import zjitc.domain.Order;
import zjitc.domain.User;

import java.util.List;

public interface OrderMapper {
    @Select("SELECT * FROM orders")
    @Results({
            @Result(id = true,column = "oid",property = "id"),
            @Result(column = "ordertime",property = "ordertime"),
            @Result(column = "total",property = "total"),
            @Result(
                    property = "user",
                    column = "uid",
                    javaType = User.class,
                    one=@One(select = "zjitc.mapper.UserMapper.findById")
            )
    })
    public List<Order> findAll();
    @Select("SELECT * FROM orders WHERE uid=#{uid}")
    public List<Order> findByUid(int uid);
//    @Select("SELECT *,o.id oid FROM orders o,USER u WHERE o.uid=u.id")
//    @Results({
//            @Result(id = true,column = "oid",property = "id"),
//            @Result(column = "ordertime",property = "ordertime"),
//            @Result(column = "total",property = "total"),
//            @Result(column = "username",property = "user.username"),
//            @Result(column = "password",property = "user.password"),
//            @Result(column = "salt",property = "user.salt")
//    })
//    public List<Order> findAll();
}
